package tech.yangzhijie.basic.ioc;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;
import java.util.List;

public class Tests {

    public static void main(String[] args) {
        ApplicationContext app = new ClassPathXmlApplicationContext("classpath:ioc.xml");
        UserService userService = app.getBean("userService", UserService.class);
        User user = userService.selectById(2);
        System.out.println(user+"\n=======================");
        List<User> users = userService.selectAll();
        users.forEach(System.out::println);

        if(app.containsBean("userService")){
            System.out.println("包含userService");
        }else {
            System.out.println("不包含userService");
        }
        if(app.isSingleton("userService")){
            System.out.println("userService是单例");
        }else {
            System.out.println("userService不是单例");
        }

        if(app.isPrototype("userService")){
            System.out.println("userService是prototype");
        }else {
            System.out.println("userService不是prototype");
        }

        if(app.isTypeMatch("userService",UserService.class)){
            System.out.println("userService是UserService类型");
        }else {
            System.out.println("userService不是UserService类型");
        }

        System.out.println(app.getType("userService"));
        System.out.println(app.getAliases("userService").length);
    }
}
